#!/bin/bash

ips=(172.16.236.128 172.16.236.125 172.16.236.127 172.16.236.129 172.16.236.126 172.16.236.130)
password=Xzdream18779175574
createCluster="/usr/local/redis-6.2.5/src/redis-cli -a $password --cluster create "

PROC_NAME=redis-server

wget https://download.redis.io/releases/redis-6.2.5.tar.gz

for((i=0;i<${#ips[@]};i++)) do
	createCluster="$createCluster${ips[i]}:637$i "
	./expect.sh ${ips[i]} root $password redis-6371.conf /root/shell $i
done;

createCluster="$createCluster --cluster-replicas 1"

for((i=0;i<${#ips[@]};i++)) do
	ProcNumber=`sshpass -p $password ssh  root@${ips[i]} "ps -ef |grep -w $PROC_NAME|grep -v grep|wc -l"`
	if [ $ProcNumber -le 0 ];then
	   echo "testPro is not run"
	   sshpass -p $password ssh  root@${ips[i]} "/usr/local/redis-6.2.5/src/redis-server /usr/local/redis-6.2.5/cluster/conf/redis-637$i.conf"
	else
	   echo "testPro is  running.."
	fi
done;

sshpass -p $password ssh  root@${ips[0]} "$createCluster"
